/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sbcc.edu.blackjack.utility;

import java.util.Random;

/**
 *
 * @author Ray Kolbe
 */
public class XORShiftRandom extends Random {

    /*
     *  A subclass of java.util.Random that implements the
     *  XORShift algorithm found in 2003 by George Marsaglia
     */
    private long seed;

    public XORShiftRandom(long seed) {
        this.seed = seed;
    }

    protected int next(int nbits) {
        long x = seed;
        x ^= (x << 21);
        x ^= (x >>> 35);
        x ^= (x << 4);
        seed = x;
        x &= ((1L << nbits) - 1);
        return (int) x;
    }
    
}
